package com.razorthink.shell.commands.essential;

import com.razorthink.shell.core.AbstractCommand;
import com.razorthink.shell.core.EnvironmentVariable;
import com.razorthink.shell.utils.CommandLogger;

public class Env extends AbstractCommand {

	public Env(String baseCommand, int params) {
		super(baseCommand, params);
	}

	@Override
	public String getUsage() {
		return "env [env var name]";
	}

	@Override
	public void execute() {
		Object var = super.getCommandParser().getParams().get(0);
		if (var.equals("$")) {
			for (EnvironmentVariable v : super.getAllEnvVars()) {
				CommandLogger.logInfo(v.getVariableName() + "=" + v.getValue());
			}
		} else {
			EnvironmentVariable env = super.getEnvVar(var);
			if (env == null) {
				CommandLogger.logInfo("env var '" + var + "' not set");
			} else {
				CommandLogger.logInfo(env.getVariableName() + "="
						+ env.getValue());
			}
		}
	}

	@Override
	public String getDescription() {
		return "gets a specific env var \n\t\t(Or all env vars if param is '$')";
	}

}
